<template>
  <div>
    <van-address-edit
      :area-list="areaList"
      show-postal
      show-delete
      show-set-default
      :address-info="handlist"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="handSave"
      @delete="handDelete"
    />
  </div>
</template>

<script>
import Vue from "vue";
import { AddressEdit } from "vant";
import { nanoid } from "nanoid";
import { Toast } from "vant";
import { areaList } from "@vant/area-data";
Vue.use(AddressEdit);
export default {
  created() {
    console.log(this.$route.query.i);  
    this.idx = this.$route.query.i;
  },
  data() {
    return {
      idx: 0,
      areaList, //地区数据
      nanoid,
      //  handlist: {
      //     id: 1,
      //     name: "张三分",
      //     tel: "15846855512",
      //     addressDetail: "大西洋国际",
      //     areaCode: "320583",
      //     postalCode: "400000",
      //     isDefault: true,
      // },
    };
  },
  computed: {
    handlist() {
      if (this.idx != -1) {
        return this.$store.state.address.list[this.idx];
      }
    },
  },
  methods: {
    handSave(content) {
      let { province, city, county, addressDetail } = content;
      content.address = province + city + county + addressDetail;
      content.id = parseInt(Math.random() * 10000);
      let idx = this.idx;
      this.$store.commit("address/addAddressmut", { obj: content, idx });
      console.log(content);
      this.$router.push("/site");
    },
    handDelete(content) {
      let idx = this.idx;
      this.$store.commit("address/delAddressmut", {content,idx});
      this.$router.push({
        path: "/site/",
      });
    },
  },
};
</script>

<style lang="less" scoped></style>
